package com.cskaoyan.market.admin.controller;

import com.cskaoyan.market.admin.service.MarketDashBoardService;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yuanixn2158@163.com
 * @since 2023/05/08 11:23
 */
@RestController
@RequestMapping("/admin")
public class AdminDashBoardController{
    @Autowired
    private MarketDashBoardService dashBoardService;

    @GetMapping("/dashboard")
    private void dashboard(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //{"data":{"goodsTotal":240,"userTotal":32,"productTotal":245,"orderTotal":518}}
        Map<String,Long> result=new HashMap<>();
        result.put("goodsTotal",dashBoardService.getGoodsTotal());
        result.put("userTotal",dashBoardService.getUserTotal());
        result.put("productTotal",dashBoardService.getProductTotal());
        result.put("orderTotal",dashBoardService.getOrderTotal());
        Object ok= ResponseUtil.ok(result);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(ok));

    }
}
